var indexModule = angular.module("indexModule",['ui.bootstrap','ngRoute']);
var loginMoudel = angular.module('login_moudel',[]);

var post_httpUrl = window.location.origin;

var config = {

    logoutHttpMsg: "注销用户成功！！",
    addHttpMsg: "添加成功！",
    saveHttpMsg: "保存成功！",
    delHttpMsg: "删除成功！",
    shareHttpMsg: "分享成功！",
    modifyHttpMsg: "删除成功！",
    saveTipHttpMsg: "正在为你保存，请稍后......",
    modifyWebTipHttpMsg: "网站名称和网站域名不能为空！",
    modifyAdTipHttpMsg: "广告词和广告类型不能为空！",

    confirmDelete:"确认删除？",

    adMiss_nameVal:"请输入添加的广告词！",
    adMiss_typeVal:"请选择对应的广告类型！",
    talkMissVal:"请输入标题和内容！",
    onloginMissVal:"请正确输入用户名和密码！",
    successRegist:"恭喜您注册成功！",
    usersMiss_nameVal:"用户名不能为空！",
    usersMiss_pwdVal:"密码不能为空！",
    mustNum:"单价必须输入数字！",
    pwdVal_isSame:"两次输入的密码不一致，请重新输入！",
    pwdVal_isRight:"密码必须是数字和字母的6-16位数！",

    //保存登陆用户名字的cookis
    loginName:"loginName",
    //登陆地址
    loginFileUrl: "login.html",
    //登陆接口地址
    login_httpUrl:post_httpUrl + '/onlogin',
    regist_httpUrl:post_httpUrl + '/regist',
    logout_httpUrl:post_httpUrl + '/logout',
    //用户列表等接口地址
    usersList_httpUrl:post_httpUrl + '/users/list',
    usersAdd_httpUrl:post_httpUrl + '/users/add',
    usersEdit_httpUrl:post_httpUrl + '/users/edit',
    usersDel_httpUrl:post_httpUrl + '/users/del',
    usersModify_httpUrl:post_httpUrl + '/users/modify',
    //网站列表等接口地址
    webList_httpUrl:post_httpUrl + '/web/list',
    webSave_httpUrl:post_httpUrl + '/web/save',
    webDel_httpUrl:post_httpUrl + '/web/del',
    //广告列表等接口地址
    adList_httpUrl:post_httpUrl + '/ad/list',
    adSave_httpUrl:post_httpUrl + '/ad/save',
    adDel_httpUrl:post_httpUrl + '/ad/del',
    adShare_httpUrl:post_httpUrl + '/ad/share',
    adShareList_httpUrl:post_httpUrl + '/ad/shareList',
    //留言列表等接口地址
    talkList_httpUrl:post_httpUrl + '/talk/list',
    talkAll_httpUrl:post_httpUrl + '/talk/all',
    talkSave_httpUrl:post_httpUrl + '/talk/save',
    talkDetail_httpUrl:post_httpUrl + '/talk/detail',
    talkDel_httpUrl:post_httpUrl + '/talk/del',
    talkContent_httpUrl:post_httpUrl + '/talk/content',
    //公告列表等接口地址
    noticeList_httpUrl:post_httpUrl + '/notice/list',
    noticeAll_httpUrl:post_httpUrl + '/notice/all',
    noticeSave_httpUrl:post_httpUrl + '/notice/save',
    noticeDetail_httpUrl:post_httpUrl + '/notice/detail',
    noticeDel_httpUrl:post_httpUrl + '/notice/del',
    noticeContent_httpUrl:post_httpUrl + '/notice/content',

    //首页公告条数
    indexNotice_num: 11,
    indexTalk_num: 11,

    //用户类型的权限
    adminUser: 1,
    defaultUser: 0,

    //不同用户登陆跳转到的路径不同
    adminUser_index: "admin.html",
    defaultUser_index: "index.html",

    //网站广告的分享与否
    isShareAd: 1,
    noShareAd: 0,

    topHeadTit: "网站广告资源管理平台",
    editor_tools : ['bold', 'italic', 'underline', 'forecolor', 'backcolor', 'fontfamily', 'fontsize','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','link','insertimage']
};

//日期 返回2012-12-12 num表示前几天，num=0表示今天，-1表示昨天
function getDateString(num){
    var nowDate = new Date();
    var now_date = nowDate.getDate();
    var start_date = new Date(nowDate.setDate(now_date + parseInt(num)));
    var year = start_date.getFullYear();
    var month = start_date.getMonth()+1;
    if(month < 10) month = "0" + month;
    var date = start_date.getDate();
    if(date <10) date = "0" + date;
    return year + "-" + month + "-" + date;
};

//加载js
function addScript(url,callback){
    var elt = document.createElement("script");
    elt.src = url;
    elt.anysc = true;
    if(elt.onload==null){
        elt.onload = function(){
            typeof callback=='function'&&callback();
        }
    }else{
        elt.onreadystatechange = function(){
            if(elt.readyState=="loaded" || elt.readyState=="complete"){
                typeof callback=='function'&&callback();
            }
        }
    }
    document.getElementsByTagName("body")[0].appendChild(elt);
}

//处理http post请求
function postHttp($http,url,postData,callback){
    $http({
        method:"post",
        url:url,
        data:postData
    }).success(function(data){
        if(data.status === 1){
            callback(data);
        }else if(data.status === 0){
            alert(data.error);
        }else if(data.status === -1){
            var timeOutCookie = $.cookie("timeOut");
            if(timeOutCookie === ""){
                $.cookie("timeOut","timeOut");
                alert(data.error);
                window.location.href = "login.html";
            }else{
                $.cookie("timeOut","");
            }
        };
    });
};